package com.witmed.home.view.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.witmed.home.databinding.ItemHomeBinding
import com.witmed.lib_common.utils.ImageUtils
import com.witmed.lib_http.entity.VideoList
import com.witmed.lib_http.entity.VideoListItem

class VideoAdapter(val context:Context,val list:VideoList,val clickListener:ItemClickListener,
    val longClickListener:LongClickListener):
    RecyclerView.Adapter<VideoAdapter.VideoViewHolder>() {

    lateinit var itemdb:ItemHomeBinding
    inner class VideoViewHolder(view:View):RecyclerView.ViewHolder(view){
        var img=itemdb.iv
        var title=itemdb.tvTitle
        //var vp=itemdb.vp
    }

    //创建ViewHolderd对象
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VideoViewHolder {
        itemdb= ItemHomeBinding.inflate(LayoutInflater.from(context),parent,false)
        return VideoViewHolder(itemdb.root)
    }

    override fun getItemCount(): Int {
        return list.size
    }


    override fun onBindViewHolder(holder: VideoViewHolder, position: Int) {
        val video = list.get(position)
        holder.title.text=video.title
        ImageUtils.loadIamge(context,video.videomainimag,holder.img)
        /*holder.vp.apply {
            //延迟设置播放地址
            setUpLazy(video.videopath,true,null,
                null,video.title)
            titleTextView.visibility=View.GONE
            backButton.visibility=View.GONE
            //防止item错位
            playPosition=position
            //设置自动横竖屏
            isAutoFullWithSize=true
            //音视频焦点是否释放
            isReleaseWhenLossAudio=false

            setDismissControlTime(100)

            //第一项自动播放
            if(position==0){
                startPlayLogic()
            }

        }*/




        holder.itemView.setOnClickListener {
            clickListener.onClick(position,video)
        }
        holder.itemView.setOnLongClickListener {
            longClickListener.onLongClick(video)
            true
        }
    }

    interface ItemClickListener{
        fun onClick(position: Int,entity:VideoListItem)
    }

    interface LongClickListener{
        fun onLongClick(entity:VideoListItem)
    }
}